package cn.chinaflame.pagodas.web;


import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.google.common.base.Strings;
import com.google.common.collect.Lists;

import cn.chinaflame.pagodas.Result.Result;
import cn.chinaflame.pagodas.annotation.ApiDoc;
import cn.chinaflame.pagodas.dto.PaBlessDto;
import cn.chinaflame.pagodas.dto.PaBlessQryDto;
import cn.chinaflame.pagodas.service.PaBlessService;
import cn.chinaflame.pagodas.service.PaOrderitemService;
import cn.chinaflame.pagodas.service.PaProductPointService;

/**
 * 祝福相关接口
 * @author	boming
 * @date	2018年6月21日 下午1:55:26
 */
@RestController
@Transactional(rollbackFor = Exception.class)
@RequestMapping(value="/openapi/v1/pagodas/bless/")
public class OpenPaBlessAPI {
	
	
	private static final Logger log = LoggerFactory.getLogger(OpenPaBlessAPI.class);

	@Autowired
	private PaBlessService paBlessService;
	@Autowired
	private PaProductPointService paProductPointService;
	@Autowired
	private PaOrderitemService paOrderitemService;
	
	/**
	 * 查询我的祝福列表
	 * @param memberId	会员id
	 * @param openid	openid
	 * @return
	 */
	@GetMapping(value="query/list")
	@ApiDoc(PaBlessDto.class)
	public Object query(String memberId,String openid){
		log.info("查询我的祝福列表memberId:{},openid:{}", memberId, openid);
		List<PaBlessDto> dtos = paBlessService.query(memberId, openid);
		return Result.create(dtos);
	}
	/**
	 * 查询我的祝福列表（分类）
	 * @param id		祝福id
	 * @param memberId	会员id
	 * @param openid	openid
	 * @param mobile	手机号
	 * @param orderType	订单类型（祝福/供灯）
	 * @return
	 */
	@GetMapping(value="query/list/detail")
	@ApiDoc(PaBlessQryDto.class)
	public Object query(String id, String memberId, String openid, String mobile, String orderType){
		log.info("查询祝福详情列表id:{},memberId:{},openid:{},mobile:{},orderType:{}", id, memberId, openid, mobile, orderType);
		boolean aa = !Strings.isNullOrEmpty(id);
		boolean bb = !Strings.isNullOrEmpty(memberId);
		boolean cc = !Strings.isNullOrEmpty(openid);
		boolean dd = !Strings.isNullOrEmpty(mobile);
		
		boolean b = !Strings.isNullOrEmpty(id) || !Strings.isNullOrEmpty(memberId) || !Strings.isNullOrEmpty(openid)
				|| !Strings.isNullOrEmpty(mobile);
		if(!b) {
			log.error("查询祝福详情列表，必要参数为空");
			return Result.create(Lists.newArrayList());
		}
		List<PaBlessQryDto> dtos = paBlessService.queryDetail(id, memberId, openid, mobile, orderType);
		return Result.create(dtos);
	}

	/**
	 * 微信公众号我的供灯
	 * @param openid		openid
	 * @param memberId		会员id
	 * @return
	 */
	@GetMapping("myLamp")
	@ApiDoc(Result.class)
	public Object myLamp(String openid,String memberId){
		log.info("我的供灯openid:{},会员id{}",openid,memberId);
		List<Map<String, Object>>  list =paBlessService.myLamp(openid, memberId);
		return Result.create(list);
	}
	/**
	 * 闪烁加持接口
	 * @param orderitemId		订单详情id
	 * @return
	 */
	@GetMapping("flash")
	@ApiDoc(Result.class)
	public Object flash(String orderitemId){
		log.info("闪烁加持接口orderitemId:{}", orderitemId);
		return paOrderitemService.flash(orderitemId);
	}
	/**
	 * 修改祝福语接口
	 * @param orderitemId
	 * @param beWishedMemo
	 * @return
	 */
	@GetMapping("modify/memo")
	@ApiDoc(Result.class)
	public Object modifyBlessMemo(String orderitemId, String beWishedMemo){
		log.info("修改祝福语orderitemId:{},beWishedMemo:{}", orderitemId, beWishedMemo);
		return paOrderitemService.modifyBewishedMemo(orderitemId, beWishedMemo);
	}
}
